// pages/organization/admin/kick.js
var app = getApp();
var util = require("../../../utils/util.js")
Page({

  /**
   * 页面的初始数据
   */
  data: {

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var org_id = options.org_id;
    var yuyue_session = wx.getStorageSync('yuyue_session');
    var that = this;
    //获取组内成员
    wx.request({
      url: app.globalData.default_url,
      data: {
        action: "api.v1.organization.member_list",
        org_id: org_id,
        yuyue_session: yuyue_session,
      },
      success: function (res) {//连接成功
        if (res.data) {
          if (res.data.op == "member_list") {//请求成功
            console.log(res.data.data);
            that.setData({
              member_list: res.data.data,
              org_id: org_id,
            })
          } else {//请求失败
            wx.showModal({
              title: '请求失败',
              content: '获取组员信息失败',
              showCancel: false,
              confirmText: "重试",
              success: function (res) {
                if (res.confirm) {
                  that.onLoad();
                  return;
                } else {
                  wx.navigateBack({
                    delta: 1,
                  })
                }
              }
            })
          }
        }
      }, fail: function (res) {
        util.neterror_Modal(function () {
          that.onLoad();
          return;
        })
      }
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  //服务器
  //踢人
  kick_request: function (option) {
    console.log(option);
    var yuyue_session = option.target.dataset.join_session;
    var org_id = this.data.org_id;
    var that = this;
    wx.showModal({
      title: '请出组织',
      content: '确认将该成员请出组织？',
      success: function (res) {
        if (res.confirm) {
          wx.request({
            url: app.globalData.default_url,
            data: {
              action: "api.v1.organization.kick_member",
              org_id: org_id,
              yuyue_session: yuyue_session,
            },
            success: function (res) {
              if (res.data.op != "fail") {
                wx.showModal({
                  title: '操作成功',
                  content: '成功将该成员请出',
                  showCancel: false,
                  confirmText: '确定',
                  confirmColor: '',
                  success: function (res) {
                    if (res.confirm) {
                      wx.navigateBack({

                      })
                    }
                  },
                  fail: function (res) { },
                  complete: function (res) { },
                })
              } else {
                wx.showModal({
                  title: "操作失败",
                  content: res.data.reason,
                  confirmText: "重试",
                  success: function (res) {
                    if (res.confirm)
                      that.kick_request(yuyue_session);
                  }
                })
              }
            }
          })
        }
      }
    })

  }
})